package com.tarena.lbs.user.controller;

import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.user.pojo.param.UserGroupParam;
import com.tarena.lbs.user.pojo.po.UserGroupPO;
import com.tarena.lbs.user.pojo.query.UserGroupQuery;
import com.tarena.lbs.user.pojo.vo.UserGroupVO;
import com.tarena.lbs.user.service.UserGroupService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.rmi.CORBA.Util;
import javax.servlet.http.HttpServletRequest;

/**
 * 用户人群业务相关
 */
@Api(tags = "用户人群管理")
@Slf4j
@RestController
@RequestMapping("/admin/basic/userGroup/")
public class UserGroupController {
    @Autowired
    private UserGroupService userGroupService;
    @Autowired
    private HttpServletRequest request;
    @ApiOperation("人群数据分页列表")
    @PostMapping("list")
    public Result<PageResult<UserGroupVO>> pageList(@RequestBody UserGroupQuery query)
            throws BusinessException{
        return new Result<>(userGroupService.pageList(query));

    }
    @ApiOperation("保存人群数据")
    @PostMapping("save")
    public Result<Void> save(@RequestBody UserGroupParam param)throws BusinessException
    {
        if (param == null || param.getGroupName() == null || param.getGroupName().isEmpty()) {
            log.error("参数为空");

        }
        log.debug("入参人群数据：{}",param);

        Integer result =userGroupService.saveUserGroup(param);
        if(result >0)
        {return Result.success();}
        else{return Result.fail();}
    }
}
